package com.home.action;

import java.util.List;

import javax.servlet.http.HttpServletRequest;

import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Controller;
import org.springframework.web.bind.annotation.RequestMapping;

import com.home.common.Cache;
import com.home.model.HouseType;
import com.home.service.HouseTypeService;

@Controller
public class HouseTypeAction {
	@Autowired
	private HouseTypeService houseTypeService;

	@RequestMapping("/admin/housetype/list.do")
	public String getAll(HttpServletRequest request) {
		List<HouseType> typeList = this.getTypeService().getList();
		request.setAttribute("list", typeList);
		return "/admin/housetype/list";
	}

	@RequestMapping("/admin/housetype/save.do")
	public String getAll(HouseType type) {
		if (type != null) {
			this.getTypeService().save(type);
		}
		Cache.getInstance().refreshHouseType();
		return "redirect:/admin/housetype/list.do";
	}

	@RequestMapping("/admin/housetype/get.do")
	public String get(Integer id, HttpServletRequest request) {
		if (id != null) {
			HouseType type = this.getTypeService().getType(id);
			request.setAttribute("obj", type);
		}
		return "/admin/housetype/obj";
	}

	@RequestMapping("/admin/housetype/delete.do")
	public String delete(Integer id, HttpServletRequest request) {
		if (id != null) {
			HouseType t=new HouseType();
			t.setId(id);
			this.getTypeService().delete(t);
		}
		return "redirect:/admin/housetype/list.do";
	}
	
	
	public HouseTypeService getTypeService() {
		return houseTypeService;
	}

	public void setTypeService(HouseTypeService typeService) {
		this.houseTypeService = typeService;
	}

}
